#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

map<string, vector<string> > aClass;

int main() {
  int i,j ,k;

   
  // We first read all the words, and separate
  // them by anagram equivalence class.
  ifstream fileInput("wl.txt"); 
  
  string word;
  while (fileInput >> word) {
    string originalWord = word;
    // sort all the letters in the word to get a pivot of the class.

    sort(word.begin(), word.end());
    // add it to the corresponding class (assuming no repeated words).
    aClass[word].push_back(originalWord);
  } 

  // Now we run our program until getting "0".
  string input;
  while (cin >> input) {
    if (input == "0") break;

    sort(input.begin(), input.end());
    vector<string> res = aClass[input];
    // We print the answer.
    for (i = 0; i < res.size(); ++i) {
      if (!i) cout << "[";
      else cout << ",";
      cout << res[i];
    } cout << "]" << endl;
  }

  return 0;
}
